<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/functions.tld" prefix="fun" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<style type="text/css">
</style>
<script type="text/javascript">
	function addOrUpdateUser(){
		var r = $('#userForm').form('validate');
		if(!r) {
			return false;
		}
	    if($('#userid').val()!='')
	    {
			$.post("user/userUpdate",$("#userForm").serializeArray(),function(data){
				if(data.result == 'succ'){
					$('#MyPopWindow').window('close');
					$('#userTable').datagrid('reload');  
					$.messager.alert('提示','保存成功','info');
				}else{
					if(data.reason == 'exists'){
						$.messager.alert('提示','已经存在','info');
					}else{
						$.messager.alert('提示','保存失败','info');
					}
				}
			});	
	    }else
	    {
			$.post("user/userAdd",$("#userForm").serializeArray(),function(data){
				if(data.result == 'succ'){
					$('#MyPopWindow').window('close');
					$('#userTable').datagrid('reload');  
					$.messager.alert('提示','保存成功','info');
				}else{
					if(data.reason == 'exists'){
						$.messager.alert('提示','已经存在','info');
					}else{
						$.messager.alert('提示','保存失败','info');
					}
				}
			});   	
	    }

	}
	var npass = null;
	$.extend($.fn.validatebox.defaults.rules, {
	    loadVal: {
	        validator: function(value){
	        	npass = value;
	            return true;
	        },
	        message: '结束日期应该大于开始日期!'
	    }
	});
	$.extend($.fn.validatebox.defaults.rules, {
	    eq: {
	        validator: function(value){
	            return (value == npass);
	        },
	        message: '两次密码输入不一致!'
	    }
	});
</script>
 	<form id="userForm" method="post" style="margin: 10;text-align: center;">
 	<input type="hidden" name="userid" value="${user.userid }"/>
 	<input type="hidden" name="delflg" value="${user.delflg }"/>
 	<input type="hidden" name="createuserid" value="${user.createuserid }"/>
 	<input type="hidden" name="creatdatetime" value='<fmt:formatDate value="${user.creatdatetime }" pattern="yyyy-MM-dd HH:mm:ss"/>'/>
	<input type="hidden" name="version" value='${user.version }'/>
	<table >
		<tr>
			<td>登陆ID：</td>
			<td><input name="username" ${empty user.userid ? "":"readonly='readonly'" } value='${user.username }' style="width: 200"
				 class="easyui-validatebox" validType="length[3,20]" required="true">
			</td>
		</tr>
	<c:choose>
		<c:when test="${empty user.userid }">
		<tr>
			<td>密码：</td>
			<td><input type="password" name="password" style="width: 200"
				class="easyui-validatebox" validType="loadVal" required="true"></td>
		</tr>
		<tr>
			<td>重复：</td>
			<td><input type="password" name="repassword"  style="width: 200"
				class="easyui-validatebox" validType="eq" required="true"></td>
		</tr>
		</c:when>
		<c:otherwise>
		<tr>
			<td>密码：</td>
			<td><input type="password" name="password"  value="${user.password }" style="width: 200" readonly="readonly"></td>
		</tr>
		</c:otherwise>
	</c:choose>
		<tr>
			<td>操作员姓名：</td>
			<td><input name="name" value="${user.name }" style="width: 200"
				validType="length[2,20]" class="easyui-validatebox" required="true">
			</td>
		</tr>
		<tr>
			<td>操作员卡号：</td>
			<td><input name="dbkey" id="dbkey" value="${user.dbkey }" style="width: 200" class="easyui-validatebox" required="true">
			</td>
		</tr>
		<tr>
			<td>角色：</td>
			<td>
	<c:forEach var="role" items="${roleList }" >
		<div style="width:100px;float:left;cursor:pointer;overflow: hidden;" title="${role.descs }" >
			<label><input type="checkbox" name="userRoles" value="${role.roleid }" ${fun:contains(user.roles,role)?"checked=checked":"" }  />${role.descs }</label>
		</div>
	</c:forEach>
			</td>
		</tr>
	</table>
	<a href="#" id="btn-back" onclick="$('#dbkey').val(findCard());" class="easyui-linkbutton" >读卡</a>
	<a href="#" id="btn-back" onclick="closeWindow();" class="easyui-linkbutton" iconCls="icon-back">返回</a>
	<a href="#" id="btn-add" onclick="addOrUpdateUser();" class="easyui-linkbutton" iconCls="icon-save">保存</a>
</form>